/**
 * Copyright (C) 2013 Daniel Gee.
 * See LICENSE.txt for more details.
 */
package com.rl.dungeon.pathing;

import com.rl.dungeon.Location;

/**
 * Pairs a Location with an fCost value, and sorts with other similar pairs based on the fCost.
 * 
 * @author Daniel Gee
 */
class CostedLocation implements Comparable<CostedLocation>
{
	/**
	 * the combined g and h cost of this location
	 */
	final int fCost;

	/**
	 * the Location in question
	 */
	final Location location;

	/**
	 * @param location
	 * @param fCost
	 */
	CostedLocation(Location location, int fCost)
	{
		this.location = location;
		this.fCost = fCost;
	}

	/**
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(CostedLocation o)
	{
		return Integer.compare((this.fCost * 100), (o.fCost * 100));
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
		{
			return true;
		}
		if (obj == null)
		{
			return false;
		}
		if (this.getClass() != obj.getClass())
		{
			return false;
		}
		CostedLocation other = (CostedLocation) obj;
		if (Double.doubleToLongBits(this.fCost) != Double.doubleToLongBits(other.fCost))
		{
			return false;
		}
		if (this.location == null)
		{
			if (other.location != null)
			{
				return false;
			}
		}
		else if (!this.location.equals(other.location))
		{
			return false;
		}
		return true;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(this.fCost);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((this.location == null) ? 0 : this.location.hashCode());
		return result;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		return "CL(" + this.fCost + ", " + this.location + ")";
	}
}